package ufro.pdssoaws;


	import org.ksoap2.SoapEnvelope;
	import org.ksoap2.serialization.PropertyInfo;
	import org.ksoap2.serialization.SoapObject;
	import org.ksoap2.serialization.SoapPrimitive;
	import org.ksoap2.serialization.SoapSerializationEnvelope;
	import org.ksoap2.transport.AndroidHttpTransport;

	public class AlumnoSOAWS {

		private static String METHOD_NAME ;
		private static String NAMESPACE ;
		private static String URL;
		/*
		 *
		 */
		public void coneccionwsPropio(){
			NAMESPACE = "http://ws";
			URL = "http://192.168.1.2:8080/ProyectoAnotacionesFinal/services/AlumnoSOA?wsdl";

		}
/**
 * Metodo que llama al metodo find del ws
 * @param cursoId
 * @return Json
 */

		public String findAlumno(int cursoId){
			coneccionwsPropio();
			METHOD_NAME = "find";
			String SOAP_ACTION = NAMESPACE + METHOD_NAME;
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

			PropertyInfo findcursoId = new PropertyInfo();

			findcursoId.setName("cursoId");
			findcursoId.setValue(cursoId);
			findcursoId.setType(int.class);

			request.addProperty(findcursoId);

			SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
			soapEnvelope.dotNet = true;
			soapEnvelope.implicitTypes =true;
			soapEnvelope.setOutputSoapObject(request);
			AndroidHttpTransport aht = new AndroidHttpTransport(URL);
			String datosJsonString;
			try
			{
				aht.call(SOAP_ACTION, soapEnvelope);
				SoapPrimitive resultString = (SoapPrimitive)soapEnvelope.getResponse();
				datosJsonString =resultString.toString();
				return datosJsonString;
			}
			catch (Exception e)
			{
				e.printStackTrace();
				// en caso de no tener acceso al web service
				datosJsonString = "Error Conexion";}
			return datosJsonString;
		}
	}
